package merchant.space;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;


public class MerchantActivity extends TabActivity {
    /** Called when the activity is first created. */
	
	private static final int CHECKCONNECT = 1;
	private static final int NOTCONNECTED = 0;
	
	private Navigation navigation;
	
	private AlertDialog alertdialog = null;
	private ProgressDialog progressdialog = null;
	
	private MerchantActivity context;
	
	public Navigation getNavigation(){
		return navigation;
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
      	context = this;
    	setContentView(R.layout.main);
    	navigation = new Navigation();
    	  
    	 Resources res = getResources(); // Resource object to get Drawables
    	    TabHost tabHost = getTabHost();  // The activity TabHost
    	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    	    Intent intent;  // Reusable Intent for each tab

    	    intent = new Intent().setClass(this, MyCollectionsGroupActivity.class);
    	    spec = tabHost.newTabSpec("mycollectionsT").setIndicator("My Collections",
    	                      res.getDrawable(R.drawable.mycollections))
    	                  .setContent(intent);
    	    tabHost.addTab(spec);
    	   
    	    intent = new Intent().setClass(this, BrowseGroupActivity.class);
    	    spec = tabHost.newTabSpec("browseT").setIndicator("Browse",
    	                      res.getDrawable(R.drawable.browse))
    	                  .setContent(intent);
    	    tabHost.addTab(spec);

    	   
    	    intent = new Intent().setClass(this, SettingsActivity.class);
    	    spec = tabHost.newTabSpec("settingsT").setIndicator("Settings",
    	                      res.getDrawable(R.drawable.setts))
    	                  .setContent(intent);
    	    tabHost.addTab(spec);
    	    
    	    
    	   if (!isOnline())
    				  showDialog(CHECKCONNECT);
    			  
    		  
    	Log.d("SUPER CHECK2",tabHost.getCurrentTabView().getContext().toString());
    	    
    		    tabHost.setCurrentTab(3);
    	    
    	  
    	 


    }
    
    
    public boolean isOnline() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnected()) {
            return true;
        }
        return false;
    }
    
    
    @Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case NOTCONNECTED:
			
		{
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setMessage("Please, check your internet connection")
			       .setCancelable(false)
			       .setTitle("Merchant")
			       .setPositiveButton("Exit", new DialogInterface.OnClickListener() {
			           public void onClick(DialogInterface dialog, int id) {
			             context.finish();
			           }
			       });
			
			alertdialog = builder.create();
			return alertdialog;}
			
		
		
		default:
		{
			return null; 
		}  }
		
		
		
	}
    
   
    
    	
	

}